﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DrawAxis : MonoBehaviour {
	public float length;
	public float width;
	public Color lineColor;

	public Shader shader;
	private MeshFilter meshFilter;
	private MeshRenderer meshRenderer;
	private Vector3[] vertices;
	private int[] triangles;
	void Start() {
		meshFilter = GetComponent<MeshFilter>();
		meshRenderer = GetComponent<MeshRenderer>();
		meshRenderer.material.color = lineColor;
		meshRenderer.material.shader = shader;

		UpdateLine();

	}

	private void Update() {
		//UpdateLine();
	}

	public void UpdateLine() {

		vertices = new Vector3[8];

		vertices[0] = new Vector3(-length, +width);
		vertices[1] = new Vector3(+length, +width);
		vertices[2] = new Vector3(-length, -width);
		vertices[3] = new Vector3(+length, -width);

		vertices[4] = new Vector3(-width, +length);
		vertices[5] = new Vector3(+width, +length);
		vertices[6] = new Vector3(-width, -length);
		vertices[7] = new Vector3(+width, -length);

		triangles = new int[4 * 3];

		triangles[0] = 0;
		triangles[1] = 1;
		triangles[2] = 3;

		triangles[3] = 0;
		triangles[4] = 3;
		triangles[5] = 2;

		triangles[6] = 4;
		triangles[7] = 5;
		triangles[8] = 7;

		triangles[9] = 4;
		triangles[10] = 7;
		triangles[11] = 6;


		Mesh mesh = new Mesh();
		mesh.vertices = vertices;
		mesh.triangles = triangles;
		meshFilter.mesh = mesh;
	}
}
